<template>
	<view class="select-popu-container">
		<view class="mask" @click.stop="dismiss"></view>
		<view class="popup-content">
			<text class="text bottom-border" @click="navTo(1)">扫一扫</text>
			<text class="text" @click="navTo(2)">手动选择站点</text>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {};
	},
	methods: {
		dismiss() {
			console.log('dismiss');
			uni.navigateBack({
				delta: 1
			});
		},
		navTo(type) {
			if (type == 2) {
				uni.redirectTo({
					url: '../../../select_a_worksite/index'
				});
			} else if (type == 1) {
				this.appNavTo();
			}
		},
		// 扫码
		appNavTo() {
			// #ifdef APP-PLUS
			const pluginImpl = uni.requireNativePlugin('KTGPlugins-QRCode');
			if (pluginImpl) {
				pluginImpl.goToScanPage(
					{
						isQrcode: true
					},
					data => {
						console.log(data);
						console.log(data.code);
						if (data.code == 'success' && data.data) {
							const codeData = data.data;
							console.log(codeData);
							const code = codeData.split('-')[1];
							if (code) {
								uni.showModal({
									title: '确认绑定',
									content: '确认绑定当前工作站？',
									showCancel: true,
									cancelText: '取消',
									confirmText: '确认',
									success: res => {
										if (res.confirm) {
											// 用户点击确定
											this.$u.api.workstation
												.workstation({
													userId: this.vuex_user.userId,
													workstationCode: code,
													operationFlag: 'Y'
												})
												.then(res => {
													this.$u.vuex('vuex_bind_workstation_code', code);
													uni.redirectTo({
														url: '/pages/sys/build_product/index?workstationCode=' + code
													});
												})
												.catch(err => {
													console.log(err);
												});
										} else {
											// 否则点击了取消
										}
									}
								});
							}
						}
					}
				);
			} else {
				uni.showToast({
					title: '失败',
					icon: 'none'
				});
			}
			// #endif
		}
	}
};
</script>

<style lang="scss">
page {
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0);
}
.select-popu-container {
	position: fixed;
	left: 0;
	top: 0;
	right: 0;
	bottom: 0;
	width: 100%;
	height: 100%;
	position: relative;
}
.mask {
	background: rgba(0, 0, 0, 0.1);
	width: 100%;
	height: 100%;
}
.popup-content {
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	position: absolute;
	width: 100%;
	left: 0;
	bottom: 0;
}
.text {
	background: #fff;
	width: 100%;
	text-align: center;
	flex: 1;
	font-size: 28rpx;
	color: #333333;
	padding: 30rpx;
}
.bottom-border {
	border-bottom: 1px solid #eaeaea;
}
</style>
